package org.microsites.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.microsites.domain.dao.GroupDAO;
import org.microsites.domain.model.Entity;
import org.microsites.domain.model.Group;
import org.microsites.service.GroupService;

public class GroupServiceImpl extends GenericServiceImpl<Group> implements GroupService {

	private GroupDAO groupDAO;
	
	@Override
	public Group getRoot(String name) {
		return getDAO().getRoot(name);
	}

	@Override
	public GroupDAO getDAO() {
		return groupDAO;
	}

	public void setGroupDAO(GroupDAO groupDAO) {
		this.groupDAO = groupDAO;
	}

    @Override
    public List<Entity> loadPath(Long id) {
        if (id == null) return new ArrayList<Entity>();

        Group d = this.load(id);
        if (d == null) return new ArrayList<Entity>();
        
        List<Entity> list = this.loadPath(d.getParent());
        list.add(d);

        return list;
    }
}
